// components/search-view/search-view.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    autofocus:false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //获取页面路径
    getRoute(){
      var pages = getCurrentPages();
      var currentpages = pages[pages.length-1];
      var url = currentpages.route;
      var array =url.split("/");
      var route=array[array.length-1];
      return route
    },
    onFocus(){
      var route = this.getRoute();
      if(route != "search"){
        wx.navigateTo({
          url: '/pages/search/search'
        })
                            }
    }

  },
  lifetimes:{
    attached(){
      var route = this.getRoute();
      if(route == "search"){
        this.setData({
          autofocus:true
        })
      }
    }
  }
})
